package com.hdu.point_offer;

public class lcr168 {
    class Solution {
        public int nthUglyNumber(int n) {
            int[] ans = new int[n + 1];
            ans[1] = 1;
            for (int i = 2, index2 = 1, index3 = 1, index5 = 1; i <= n; i++)
            {
                int num2 = ans[index2] * 2;
                int num3 = ans[index3] * 3;
                int num5 = ans[index5] * 5;
                int num = Math.min(num2, Math.min(num3, num5));
                ans[i] = num;
                if (num == num2) index2++;
                if (num == num3) index3++;
                if (num == num5) index5++;
            }
            return ans[n];
        }
    }
}
